package com.yehuo.app.controller;

import com.alibaba.druid.util.StringUtils;
import com.yehuo.app.entity.dto.SelectWithdrawalDto;
import com.yehuo.app.model.R;
import com.yehuo.app.model.Result;
import com.yehuo.app.service.WthdrawalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 提现控制器
 */
@RestController
@RequestMapping("/wthdrawal")
public class WthdrawalController {
    @Autowired
    private WthdrawalService wthdrawalService;

    /**
     * 提现列表
     * @param selectWithdrawalDto
     * @return
     */
    @RequestMapping("/select")
    public R selectWithdrawals(SelectWithdrawalDto selectWithdrawalDto){
        if(selectWithdrawalDto == null){
            selectWithdrawalDto = new SelectWithdrawalDto();
        }
        return wthdrawalService.selectWithdrawals(selectWithdrawalDto);
    }

    /**
     *审核提现
     * @param wthdrawalId
     * @return
     */
    @RequestMapping("/checkWithdrawal/{wthdrawalId}/{type}")
    public Result checkWithdrawal(@PathVariable("wthdrawalId") String wthdrawalId,@PathVariable("type")Integer type) {
        if (StringUtils.isEmpty(wthdrawalId)) {
            Result r = new Result();
            r.setCode(0);
            r.setMsg("wthdrawalId is null");
            r.setResult("订单Id 为空");
            return r;
        }
        return wthdrawalService.checkWithdrawal(wthdrawalId,type);
    }

    /**
     * 获取自动自动提现状态
     * @return
     */
    @RequestMapping("/selectAutoCode")
    public Result selectAutoCode(){
        return wthdrawalService.selectAutoCode();
    }

    /**
     * 修改自动提现状态
     * @param status
     * @return
     */
    @RequestMapping("/autoWithdrawal/{status}")
    public Result updateAutoWithdrawal(@PathVariable("status") String status) {
        return wthdrawalService.updateAutoWithdrawal(status);
    }
}
